package test.org.spring.boot.example.dds.service;

import org.spring.boot.example.dds.DataSourceName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("userLogService")
@DataSourceName("logdb")
public class UserLogServiceImpl implements UserLogService {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	@Transactional
	public void addUserLog(Integer userId, Integer type) {
		jdbcTemplate.update("insert into user_log(user_id, type) values(?,?)", userId, type);
	}

	@Override
	public void clear() {
		jdbcTemplate.update("delete from user_log");
	}

	@Override
	public int count() {
		return jdbcTemplate.queryForObject("select count(1) from user_log", Integer.class);
	}

}
